<%@ page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<html>
	<head>
		<link href="${ctx}/css/main.css" rel="stylesheet" type="text/css" />
		<script language="javascript">
			function doDelete(action,id){
				if(confirm('是否确认删除？')){
					location.href = "${ctx}/" + action + "?id=" + id ;
				}
			}
			
			function submitAction(action){
				document.manageForm.action = action ;
				document.manageForm.submit();
			}
			
			function init(){
				document.getElementById("area").value = "";
				document.getElementById("plantName").value = "";
				document.getElementById("plantDesc").value = "";
			}
			
			function saveAction(action) {
				if(document.getElementById("plantCode").value == '') {
					alert('请输入农产品类别');
					return false;
				}
				if(document.getElementById("plantName").value == '') {
					alert('请输入农产品名');
					return false;
				}
				if(document.getElementById("provinceCode").value == '') {
					alert('请输入省份');
					return false;
				}
				var area = document.getElementById("area").value;
				if(area == '') {
					alert('请输入面积');
					return false;
				}
				if(!validateNumber()) return false;
				submitAction(action);
			}
			
			function validateNumber() {
				var area = document.getElementById("area").value;
				if(isNaN(area)) {
					alert('面积只能为数字');
					return false;
				}
				if(area.indexOf('-') > -1) {
				   alert('面积不能为负数');
				   return false;
				}
				return true;
			} 
		</script>
	</head>
	
	<body>
		<form method="post" action="" name="manageForm">
			<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
				<tr>
					<td class="td11" align="left" colspan="4">
						<input type="button" name="save" value="保存" onClick="saveAction('savePlantArea.ac')">
						<c:if test="${!empty plantArea.id}">
							&nbsp;&nbsp;<input type="button" name="delete" value="删除" onClick="doDelete('deletePlantArea.ac','${plantArea.id}')">
						</c:if>
						<c:if test="${empty plantArea.id}">
							&nbsp;&nbsp;<input type="button" name="reset" value="重置" onClick="init()">
						</c:if>
						&nbsp;&nbsp;<input type="button" name="back" value="返回" onClick="submitAction('backToPlantAreaSearch.ac')">
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						农产品类别  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="hidden" name="id" value="${plantArea.id}">
						<select name="plantCode" id="plantCode" style="width:200px">
							<c:forEach var="plantType" items="${sessionScope.T_plantTypeList}">
								<c:if test="${plantArea.plantCode == plantType.plantCode}">
									<option value="${plantType.plantCode}" selected="selected">${plantType.plantCodeName}</option>
								</c:if>
								<c:if test="${plantArea.plantCode != plantType.plantCode}">
									<option value="${plantType.plantCode}">${plantType.plantCodeName}</option>
								</c:if>
							</c:forEach>
						</select>
					</td>
					<td width="20%" class="td2">
						农产品名  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="text" name="plantName" size="35" value="${plantArea.plantName}">
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						省份  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<select name="provinceCode" id="provinceCode" style="width:200px">
							<c:forEach var="province" items="${sessionScope.T_provinceList}">
								<c:if test="${plantArea.provinceCode == province.provinceCode}">
									<option value="${province.provinceCode}" selected="selected">${province.provinceName}</option>
								</c:if>
								<c:if test="${plantArea.provinceCode != province.provinceCode}">
									<option value="${province.provinceCode}">${province.provinceName}</option>
								</c:if>
							</c:forEach>
						</select>
					</td>
					<td width="20%" class="td2">
						面积（亩）  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="text" name="area" size="35" value="${plantArea.area}" onblur="validateNumber();">
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						农产品描述  
					</td>
					<td width="100%" class="td2" colspan="3">
						<textarea name="plantDesc" rows="3" cols="80">${plantArea.plantDesc}</textarea>
					</td>
				</tr>
			</table>
			<BR>
		</form>
	</body>
</html>